

<div class="layui-form" lay-filter="layuiadmin-form-role" style="padding: 20px 30px 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">角色</label>
    <div class="layui-input-block">
      <script type="text/html" template>
        <input type="text" lay-verify="required" name="group_name" value="{{ d.params.group_name || '' }}" lay-verify="required" placeholder="角色名称" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">权限范围</label>
    <div class="layui-input-block" id="perms">

    </div>
  </div>
  <script type="text/html" template>
    <input type="hidden" name="opt" value="edit">
    <span style="display: none" id="myperms">{{ d.params.group_perm || '' }}</span>
    <input type="hidden" name="id" id="id" value="{{ d.params.group_id || '' }}">
  </script>
  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <input type="button" lay-submit lay-filter="LAY-user-role-submit" value="确认" class="layui-btn">
    </div>
  </div>
</div>

<script>
  layui.use(['admin','form'], function(){
    var $ = layui.$
            , admin = layui.admin
            ,form = layui.form
    admin.req({
      url: layui.setter.api + 'admins/perms'
      , method: 'get'
      , success: function (data) {
        if (data.code == 0) {

          var myperms = $.parseJSON($("#myperms").html());
          var info = data.data;
          var html = '';
          for (var key in info) {
            html += '<div style="color:#FF5722;position:relative;font-size: 12px;top: 5px;">'+info[key]['title']+'</div>';
            for(var k in info[key]['list']){
              var checked = ' ';
              for(var i in myperms){
                if(info[key]['list'][k]['name'] == myperms[i]){
                  checked = 'checked';
                }
              }
              html += '<input type="checkbox" name="group_perm[]" value="'+info[key]['list'][k]['name']+'" lay-skin="primary" title="'+info[key]['list'][k]['title']+'"'+checked+'>'
            }

          }
          $("#perms").html(html);
          form.render();
        }
      }
    });
  });
</script>
